function format(json) {
    var ret = [];
    var o={};

    function add(arr,data) {
        var obj={
            "id":data.id,
            "pId":data.pId,
            "name":data.name,
            "open":true,
            "children":[],
            "checked":data.checked
        }

        o[data.id]=obj
        arr.push(obj)
    }

    json.forEach(x=>{
        if (o[x.pId]){
            add(o[x.pId].children,x)
        }else {
            add(ret,x)
        }
    });

    return ret
}